<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>  
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>用户列表</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="description" content="用户列表">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<jsp:include page="../commons/top.jsp"/>
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  <script type='text/javascript' src='/sm/dwr/interface/managerAjax.js'></script>
 <script type='text/javascript' src='/sm/dwr/engine.js'></script>
  <script>
      function del(loginName){
          var form = document.getElementById("listForm");
          form.loginName.value = loginName;
          form.action = "/sm/controller/user/del";
          form.submit();
      }
      function add(form){

          if(isNull(form.loginName.value)){
              alert("请输入登录名称！");
              return false;
          }
          if(isNull(form.userName.value)){
              alert("请输入用户名称！");
              return false;
          }
          if(isNull(form.password.value)){
              alert("请输入登录密码！");
              return false;
          }
          if(isNull(form.repassword.value)){
              alert("请输入确认密码！");
              return false;
          }
          if(form.password.value!="" && form.repassword.value!=""){
              if(form.password.value!=form.repassword.value){
                 alert("登录密码与确认密码不一致！");
                 return false;
              }
          }
          if(isNull(form.role.value)){
              alert("请选择角色！");
              return false;
          }
          if(!isNull(form.phone.value)){
              if(!checkMobile(form.phone.value)){
                 alert("联系电话输入有误！");
                 return false;
              };
          }
          managerAjax.getUserListByName(form.loginName.value,callBack);
      }
      
      function callBack(userList){
          var form = document.getElementById('addForm');
          if(userList!=null && userList.length>0){
              alert("登录名已存在，请重新输入！");
              return false;
          }else{
              form.submit();
          }
      }
      function mod(id){
          window.open ('/sm/controller/user/getUser.html?id='+id, 'newwindow', 'height=400, width=400, top=200, left=500, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no') 
      }

  </script>
  <body>
  <form id="listForm" action="/sm/controller/user/" method="POST">
  <input type="hidden" name="loginName" value=""/>
  <table>
  <tr><td>用户列表</td></tr></table>
  <table>
  <tr>
      <td>选择</td>
      <td>序号</td>
      <td>登录名称</td>
      <td>用户名称</td>
      <td>角色</td>
      <td>联系电话</td>
      <td>操作</td>
  </tr>
    <c:if test="${userList!=null}">
       <c:forEach var="user" items="${userList}">
          <tr>
              <td><input type="radio" name="id" value="${user.id}" onclick="mod('${user.id}');"/></td>
              <td>${user.id}&nbsp;</td>
              <td>${user.loginName}&nbsp;</td>
              <td>${user.userName}&nbsp;</td>
              <td><c:if test="${user.role == 'user'}">普通用户</c:if>
                  <c:if test="${user.role == 'admin'}">管理员</c:if>
                  <c:if test="${user.role == 'opera'}">操作员</c:if>&nbsp;</td>
              <td>${user.phone }&nbsp;</td>
              <td><input type="button" value="删除" onclick="del('${user.loginName}');"/>&nbsp;</td>
          </tr>
          
       </c:forEach>
    </c:if>
    </table>
    </form>
    <form id="addForm" action="/sm/controller/user/add" method="POST">
    <table>
        <tr><td>添加用户</td></tr>
        <tr>
            <td>
                                        登录名称：</td>
            <td><input type="text" name="loginName" value="" maxlength="50"/>
            </td>
            </tr>
            <tr>
            <td>
                                       用户名称：</td>
            <td><input type="text" name="userName" value="" maxlength="50"/>
            </td>

        </tr>
        <tr>
            <td>
                                       密码：</td>
            <td><input type="password" name="password" value="" maxlength="50"/>
            </td>

        </tr>
        <tr>
            <td>
                                       确认密码：</td>
            <td><input type="password" name="repassword" value="" maxlength="50"/>
            </td>
        
        </tr>
        <tr>
            <td>
                                       用户角色：</td>
            <td><select name="role">
                <option value="user">普通用户</option>
                <option value="opera">操作员</option>
                <option value="admin">管理员</option>
                
            </select>
            </td>

        </tr>
        <tr>
            <td>
                                       联系电话：</td>
            <td><input type="text" name="phone" value="" maxlength="50"/></td>
        </tr>
        <tr><td>&nbsp;</td><td><input type="button" value="提交" onclick="add(addForm);"/>
        <input type="reset" value="重置"/></td></tr>
    </table>
    </form>
  </body>
</html>
